home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************/
- /* Based on the program blend.c by Phill Everson, from the ALV version */
- /* 2.1 suite of public-domain image processing programs. */
- /* Program to read a rasterfile and (optionally) a lookup table (LUT) */
- /* file produced by the program cst. Using the values from either the */
- /* rasterfile's LUTs (=default) or the input LUTs, map pixel values to */
- /* their LUT equivalents, then substitute a 1:1 mapping LUT and write */
- /* out the file. This allows interactively thresholded and contrast */
- /* stretched images to be used in programs which ignore LUTs. */
- /* */
- /* ras_remap.c */
- /* */
- /* Bryan Dawson, Keele University Geography Dept. */
- /* 30/3/89 */
- /**************************************************************************/
-
- #include <stdio.h>
- #include "defs.h"
-
- har * progname;
- har * malloc();
- nt header[8];
- nsigned char red[256],green[256],blue[256];
- ong filelen;
- nsigned char * image;
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- asremap_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
- {
- register int x,y;
- int lutfile = 0;
- FILE *f1, *f2;
-
- f1 = stdin;
- f2 = stdin;
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- while ((gc = getopt(argc, argv, "f:l:")) != EOF)
- switch (gc)
- {
- case 'f':
- if ((f1 = fopen(optarg, "r")) == NULL)
- error("Can't open %s\n", optarg);
- break;
- case 'l':
- if ((f2 = fopen(optarg, "r")) == NULL) lutfile = 0 ;
- else lutfile = 1;
- break;
- case '?':
- errflag++;
- break;
- } /* end switch */
-
- f (errflag)
- error((char *) 0, "Usage: %s: [-f imgfile] [-l LUTfile] [outfile] \n", progname);
-
- /* read rasterfile header */
- = fread(header,sizeof(int),8,f1);;
- f (header[0] != 0x59a66a95) error("This isn't a Sun rasterfile !");
- ilelen = (long)header[4];
- mage = (u_char *)malloc(filelen); /* allocate space for image data */
-
- /* if there is a LUT on the file, and it's needed, read it, else skip it */
- f ((lutfile == 0) && (header[7] == 768))
- {
- x = fread(red,1,256,f1);
- x = fread(green,1,256,f1);
- x = fread(blue,1,256,f1);
- } else x = fseek(f1,header[7],1);
-
- /* read image data */
- = fread(image,1,filelen,f1);
-
- /* if external LUTs are to be used, read them */
- f (lutfile == 1)
- {
- x = fread(red,1,256,f2);
- x = fread(green,1,256,f2);
- x = fread(blue,1,256,f2);
- }
-
- /* if there is still no LUT, create a dummy one */
- f ((lutfile == 0) && (header[6] == RMT_NONE))
- for (x=0;x<256;x++) red[x]=green[x]=blue[x] = x;
-
- emap();
- or (x=0;x<256;x++) red[x]=green[x]=blue[x] = x;
- riteit();
- ree(image);
- xit();
- }
-
- /* routine to map pixel values to their LUT equivalents */
- emap()
- {
- egister int temp;
- egister long p;
-
- or (p = 0L ; p < filelen ; p++)
- {
- temp = red[(int)*(image+p)];
- *(image+p) = temp;
- }
- }
-
- /* routine to write out the three components of a rasterfile */
- riteit()
- {
- eader[6] = 1;/* RMT_EQUAL_RGB */
- eader[7] = 768;
- write(header,4,8,stdout);
- write(red,1,256,stdout);/* greyscale image */
- write(red,1,256,stdout);
- write(red,1,256,stdout);
- write(image,1,filelen,stdout);
- }
-
-
-